load("//bzl:cpp_library.bzl", "cpp_library")

package(default_visibility = ["//visibility:public"])

cpp_library(
    name = "asm",
    hdrs = ["Asm.h"],
    deps = [
        "//folly:portability",
    ],
)

cpp_library(
    name = "atomic",
    hdrs = ["Atomic.h"],
    deps = [
        "//folly:portability",
    ],
)

cpp_library(
    name = "builtins",
    srcs = ["Builtins.cpp"],
    hdrs = ["Builtins.h"],
    deps = [
        ":windows",
        "//folly:portability",
    ],
)

cpp_library(
    name = "config",
    hdrs = ["Config.h"],
    deps = [
        "//folly:config",
    ],
)

cpp_library(
    name = "constexpr",
    hdrs = ["Constexpr.h"],
    deps = [
        "//folly:c_portability",
        "//folly:portability",
    ],
)

cpp_library(
    name = "dirent",
    srcs = ["Dirent.cpp"],
    hdrs = ["Dirent.h"],
    deps = [
        ":windows",
    ],
)

cpp_library(
    name = "event",
    hdrs = ["Event.h"],
    deps = [
        ":fcntl",
        ":windows",
        "//folly/net/detail:socket_file_descriptor_map",
        "@libevent//:event_core",
    ],
)

cpp_library(
    name = "fcntl",
    srcs = ["Fcntl.cpp"],
    hdrs = ["Fcntl.h"],
    deps = [
        ":sockets",
        ":sys_stat",
        ":windows",
        "//folly:portability",
    ],
)

cpp_library(
    name = "filesystem",
    srcs = ["Filesystem.cpp"],
    hdrs = ["Filesystem.h"],
)

cpp_library(
    name = "fmt_compile",
    hdrs = ["FmtCompile.h"],
    deps = [
        "@fmt",
    ],
)

cpp_library(
    name = "gflags",
    hdrs = ["GFlags.h"],
    deps = [
        ":config",
        "@gflags",
    ],
)

cpp_library(
    name = "gmock",
    hdrs = ["GMock.h"],
    deps = [
        ":unistd",
        ":windows",
        "//folly:portability",
        "@googletest//:gtest",
    ],
)

cpp_library(
    name = "gtest",
    hdrs = ["GTest.h"],
    deps = [
        ":unistd",
        ":windows",
        "//folly:portability",
        "@googletest//:gtest",
    ],
)

cpp_library(
    name = "iovec",
    hdrs = ["IOVec.h"],
)

cpp_library(
    name = "libgen",
    srcs = ["Libgen.cpp"],
    hdrs = ["Libgen.h"],
)

cpp_library(
    name = "libunwind",
    hdrs = ["Libunwind.h"],
    deps = [
        # TODO(kgk): Enable once @libunwind is added to bcr. See:
        # https://github.com/bazelbuild/bazel-central-registry/issues/3655
        # "@libunwind",

        # TODO(kgk): Enable once @jemalloc is added to bcr. See:
        # https://github.com/bazelbuild/bazel-central-registry/issues/3757
        # "@jemalloc",
    ],
)

# TODO(kgk): Support jemalloc and FOLLY_USE_JEMALLOC define here.
cpp_library(
    name = "malloc",
    srcs = ["Malloc.cpp"],
    hdrs = ["Malloc.h"],
    deps = [
        ":config",
        "//folly:c_portability",
    ],
)

cpp_library(
    name = "math",
    hdrs = ["Math.h"],
)

cpp_library(
    # @shim
    name = "memory",
    hdrs = ["Memory.h"],
    deps = ["//folly:memory"],
)

cpp_library(
    name = "openat2",
    srcs = ["openat2.c"],
    hdrs = ["openat2.h"],
    deps = [
        "//folly:config",
    ],
)

cpp_library(
    name = "openssl",
    srcs = ["OpenSSL.cpp"],
    hdrs = ["OpenSSL.h"],
    deps = [
        ":windows",
        "//folly:portability",
        "@openssl//:crypto",
        "@openssl//:ssl",
    ],
)

cpp_library(
    name = "sched",
    srcs = ["Sched.cpp"],
    hdrs = ["Sched.h"],
    deps = [
        "//folly:portability",
    ],
)

cpp_library(
    name = "pthread",
    srcs = ["PThread.cpp"],
    hdrs = ["PThread.h"],
    linkopts = select({
        "@platforms//os:windows": [],
        "//conditions:default": ["-pthread"],
    }),
    deps = [
        ":config",
        ":sched",
        ":time",
        ":windows",
        "//folly:portability",
        "//folly/lang:assume",
        "@boost.core",
        "@boost.thread",
    ],
)

cpp_library(
    name = "sockets",
    srcs = ["Sockets.cpp"],
    hdrs = ["Sockets.h"],
    deps = [
        "//folly:portability",
        "//folly:scope_guard",
        "//folly/net:net_ops",
        "//folly/net:network_socket",
        "//folly/net/detail:socket_file_descriptor_map",
    ],
)

cpp_library(
    name = "source_location",
    hdrs = ["SourceLocation.h"],
    deps = [
        "@fmt",
    ],
)

cpp_library(
    name = "stdio",
    srcs = ["Stdio.cpp"],
    hdrs = ["Stdio.h"],
    deps = [
        ":unistd",
        "//folly:scope_guard",
    ],
)

cpp_library(
    name = "stdlib",
    srcs = ["Stdlib.cpp"],
    hdrs = ["Stdlib.h"],
    deps = [
        ":config",
        ":fcntl",
        ":sys_stat",
        ":windows",
        "//folly:c_portability",
    ],
)

cpp_library(
    name = "string",
    srcs = ["String.cpp"],
    hdrs = ["String.h"],
    deps = [":config"],
)

cpp_library(
    name = "sys_file",
    srcs = ["SysFile.cpp"],
    hdrs = ["SysFile.h"],
    deps = [
        ":windows",
    ],
)

cpp_library(
    name = "sys_membarrier",
    srcs = ["SysMembarrier.cpp"],
    hdrs = ["SysMembarrier.h"],
    deps = [
        ":sys_syscall",
        "//folly:portability",
    ],
)

cpp_library(
    name = "sys_mman",
    srcs = ["SysMman.cpp"],
    hdrs = [
        "SysMman.h",
    ],
    linkopts = select({
        "@platforms//os:windows": [],
        "//conditions:default": ["-lrt"],
    }),
    deps = [
        ":windows",
        "//folly:portability",
    ],
)

cpp_library(
    name = "sys_resource",
    srcs = ["SysResource.cpp"],
    hdrs = ["SysResource.h"],
    deps = [
        ":sys_time",
        ":windows",
    ],
)

cpp_library(
    name = "sys_stat",
    srcs = ["SysStat.cpp"],
    hdrs = ["SysStat.h"],
    deps = [
        ":sys_types",
        ":windows",
        "//folly:c_portability",
    ],
)

cpp_library(
    name = "sys_syscall",
    hdrs = ["SysSyscall.h"],
    deps = [
        "//folly:c_portability",
        "//folly:portability",
    ],
)

cpp_library(
    name = "sys_time",
    srcs = ["SysTime.cpp"],
    hdrs = ["SysTime.h"],
    deps = [":windows"],
)

cpp_library(
    name = "sys_types",
    hdrs = ["SysTypes.h"],
)

cpp_library(
    name = "sys_uio",
    srcs = ["SysUio.cpp"],
    hdrs = ["SysUio.h"],
    deps = [
        ":config",
        ":iovec",
        ":sockets",
        ":sys_file",
        ":sys_types",
        ":unistd",
        "//folly:scope_guard",
    ],
)

cpp_library(
    name = "syslog",
    hdrs = ["Syslog.h"],
)

cpp_library(
    name = "time",
    srcs = ["Time.cpp"],
    hdrs = ["Time.h"],
    linkopts = select({
        "@platforms//os:windows": [],
        "//conditions:default": ["-lrt"],
    }),
    deps = [
        ":config",
        ":windows",
        "//folly:c_portability",
        "//folly:likely",
        "//folly:utility",
    ],
)

cpp_library(
    name = "unistd",
    srcs = ["Unistd.cpp"],
    hdrs = ["Unistd.h"],
    deps = [
        ":sockets",
        ":sys_types",
        ":windows",
        "//folly:portability",
        "//folly:scope_guard",
        "//folly/net/detail:socket_file_descriptor_map",
    ],
)

cpp_library(
    name = "windows",
    hdrs = ["Windows.h"],
)
